package com.practice.线程池;
import java.util.concurrent.*;
/**
 * Created by IntelliJ IDEA2021.3
 * @Author: Tenghw
 * @Date: 2022/11/06  16:00
 * @Description: new ThreadPoolExecutor()来创建线程池，建议使用这种方式。
 */
public class Demo4 {
    public static void main(String[] args) {
        //返回类型为ThreadPoolExecutor或ExecutorService
        ExecutorService pool1 = new ThreadPoolExecutor(2, 4, 2000L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>());
        //因为默认的拒绝策略是AbortPolicy，且采用默认的线程工厂，所以上下两者申明等价
        ExecutorService pool2 = new ThreadPoolExecutor(2,4,2000L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        //还可以为无界阻塞队列LinkedBlockingQueue设置容量大小，如下所示
        ExecutorService pool = new ThreadPoolExecutor(2,4,2000L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(10), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());

    }
}
